import express, { Application, Request, Response, NextFunction } from 'express'
const app:Application = express();
import {router} from './src/router/index'

//跨域
app.all('*', function(req, res, next) {  
    res.header("Access-Control-Allow-Origin", "*");  
    res.header("Access-Control-Allow-Headers", "X-Requested-With");  
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");  
    res.header("X-Powered-By",' 3.2.1')  
    res.header("Content-Type", "application/json;charset=utf-8");  
    next();  
});
app.use(router)
//404页面
app.use((req, res, next) => {
    let error:any=new Error('not fount')
    error.status=404;
    next(error);
})
//出现错误处理
app.use((err:any,req:any, res:any, next:any) => {
    res.status(err.status||500)
    res.send(err.message)
})


app.get('/', (req:Request, res:Response, next:NextFunction) => {
   res.send('Hello World!');
});
app.listen(8888, function(){
    console.log('app listening on http://localhost:8888');
})